﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.SM
{
    /// <summary>
    /// 生命附加全佑一生长期护理保险
    /// </summary>
    class Class10
    {
        /// <summary>
        /// 护理保险金给付
        /// </summary>
        /// <param name="ppa"></param>
        /// <param name="da"></param>
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period > 0 && ppa.SchemePeriodActing.SchemeActing.PeriodActings.FirstOrDefault(p => p.HolderStates.Contains("身故") && p.Period <= ppa.Period) != null)
            {
                da.Value = ppa.Amount;
            }
        }
        /// <summary>
        /// 护理状态
        /// </summary>
        /// <param name="ppa"></param>
        /// <param name="da"></param>
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {

            if (ppa.Period == 0 && ppa.SchemePeriodActing.InsurantStates.Contains("护理状态"))
            {
                da.Value = ppa.TotalFee;
                ppa.IsCurrentFinish = true;
            }
            else if (ppa.Period > 0 && ppa.PolicyActing.PeriodActings.FirstOrDefault(p=>p.SchemePeriodActing.InsurantStates.Contains("护理状态") && p.Period <=ppa.Period)!=null)
            {
                IPolicy bp = ppa.SchemePeriodActing.SchemeActing.Scheme.BasicPolicy;

                if (bp.Product.Name != "生命_金满堂终身年金保险_主")
                {
                    throw new Exception("主险必须是:生命_金满堂终身年金保险_主");
                }

                string sry = bp.SelectedColRateFactors["养老金领取年限"];

                int rage = 0;

                if (sry == "30岁")
                {
                    rage = 30;
                }
                else if (sry == "45岁")
                {
                    rage = 45;
                }
                else if (sry == "50岁")
                {
                    rage = 50;
                }
                else if (sry == "55岁")
                {
                    rage = 55;
                }
                else if (sry == "60岁")
                {
                    rage=60;
                }
                else if (sry == "65岁")
                {
                    rage=65;
                }
                else if (sry == "即期领取")
                {
                    rage=bp.Owner.Insurant.Age;
                }

                if(ppa.Age>=rage)
                {
                    double r = ppa.PolicyActing.Policy.Fee / bp.Fee * ppa.SchemePeriodActing.BasicPolicyPeriodActing.DutyActings.FirstOrDefault(p => p.Duty.Name == "养老年金保险").Value;

                    da.Value = r;
                }
            }
        }
        /// <summary>
        /// 被保险人达到护理状态豁免保险费
        /// </summary>
        /// <param name="ppa"></param>
        /// <param name="da"></param>
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            if (ppa.Period>0 && ppa.SchemePeriodActing.InsurantStates.Contains("护理状态"))
            {
                ppa.Fee = 0;
            }
        }
    }
}
